package com.mojang.mario;

import java.awt.Color;
import java.awt.Graphics;

import com.mojang.mario.sprites.Mario;

public class LoseScene extends Scene
{
    private MarioComponent component;
    private int tick;
    private String scrollMessage = "Game over!";
    
    public LoseScene(MarioComponent component)
    {
        this.component = component;
    }

    public override void init()
    {
    }

    public override void render(Graphics g, double alpha)
    {
        g.setColor(ColorExtensions.decode("#a07070"));
        g.fillRect(0, 0, 320, 240);
        int f = tick/3%10;
        if (f>=6) f = 10-f;
        g.drawImage(Art.gameOver[f,0], 160-48, 100-32, null);
        drawString(g, scrollMessage, 160-scrollMessage.Length()*4, 160, 0);
    }

    private void drawString(Graphics g, String text, int x, int y, int c)
    {
        char[] ch = text.toCharArray();
        for (int i = 0; i < ch.Length; i++)
        {
            g.drawImage(Art.font[ch[i] - 32,c], x + i * 8, y, null);
        }
    }

    private bool wasDown = true;
    public override void tick()
    {
        tick++;
        if (!wasDown && keys[Mario.KEY_JUMP])
        {
            component.toTitle();
        }
        if (keys[Mario.KEY_JUMP])
        {
            wasDown = false;
        }
    }

    public double getX(double alpha)
    {
        return 0;
    }

    public double getY(double alpha)
    {
        return 0;
    }
}